//
//  AddViewController.m
//  IOStel
//
//  Created by 宋 on 15/11/30.
//  Copyright © 2015年 宋. All rights reserved.
//

#import "AddViewController.h"
@interface myItem : NSObject <UIActivityItemSource>
@property (strong,nonatomic)NSString * text;
@end

@implementation myItem
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
    return self.text;
}

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
    return  self.text;
}

@end

@interface AddViewController ()<UITextFieldDelegate>
{
    UITextField * na;
    UITextField * te;
}
@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    na = [[UITextField alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 16, 44)];
    te = [[UITextField alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 16, 44)];
    na.text = self.names;
    te.text = self.tels;
    na.delegate = self;
    te.delegate = self;
    UIBarButtonItem * btn2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(onlin2:)];
    
    UIBarButtonItem * btn1 =[[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(onlin1:)];
    
    //self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(onlin1:)];
    
    self.navigationItem.rightBarButtonItems = @[btn2,btn1];
    
}

- (void)onlin2:(id)sender
{
    myItem * myitem = [myItem new];
    myitem.text = @"!!!";
    UIActivityViewController * con = [[UIActivityViewController alloc]initWithActivityItems:@[myitem] applicationActivities:nil];
    [self presentViewController:con animated:YES completion:nil];
}

//- (void)onlin1:(UIBarButtonItem *)btn1
- (void)onlin1:(id)sender
{
    [self.delegate inputFinshed:na.text Finshedtel:te.text];
    [self.navigationController popToViewController:self animated:YES];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [na becomeFirstResponder];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField restorationIdentifier];
    //[self.delegate inputFinshed:textField.text];
    return YES;
}


//2个输写框
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

//
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    [cell.contentView addSubview:indexPath.section == 0 ? na: te];
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @[@"姓名：",@"电话："][section];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
